package com.fengyi.homefurnish.service.impl;

import com.fengyi.homefurnish.mapper.ProAttrNameMapper;
import com.fengyi.homefurnish.pojo.ProAttrName;
import com.fengyi.homefurnish.service.ProAttrNameService;
import com.fengyi.homefurnish.utils.Log;
import com.fengyi.homefurnish.utils.Pager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品属性名业务逻辑层实现类
 */
@Service
@Transactional
public class ProAttrNameServiceImpl implements ProAttrNameService {

    @Resource
    private ProAttrNameMapper proAttrNameMapper;

    @Override
    public List<ProAttrName> getAllList() {
        return proAttrNameMapper.getAllList();
    }

    @Override
    public Integer addProAttrName(ProAttrName proAttrName) {
        try {
            Integer result = proAttrNameMapper.addProAttrName(proAttrName);
            if(result>0){
                return proAttrName.getProAttrNameId();
            }
            return -1;
        }catch (Exception e){
            Log.LOGGER.error("添加商品属性名失败："+e);
            return -1;
        }
    }

    @Override
    public Pager<ProAttrName> getProAttrNamePager(Integer offset, Integer limit, ProAttrName proAttrName) {
        Pager<ProAttrName> pager = new Pager<>();
        pager.setRows(proAttrNameMapper.getProAttrNameByPager(offset,limit,proAttrName));
        pager.setTotal(proAttrNameMapper.getProAttrNameTotal(proAttrName));
        return pager;
    }

    @Override
    public Integer updateProAttrName(ProAttrName proAttrName) {
        return proAttrNameMapper.updateProAttrName(proAttrName);
    }

    @Override
    public Integer updateProAttrNameState(ProAttrName proAttrName) {
        return proAttrNameMapper.updateProAttrNameState(proAttrName);
    }
}
